package com.zfl.thread.day05;

import java.util.concurrent.CompletableFuture;

public class CompletableFutureDemo01 {
    public static void main(String[] args) {

        CompletableFuture<Integer> completableFuture = CompletableFuture.supplyAsync(()->{
           System.out.println(Thread.currentThread().getName()+"进来了---");
           try {
               Thread.sleep(100);
           } catch (InterruptedException e) {
               throw new RuntimeException(e);
           }
           System.out.println(Thread.currentThread().getName()+"出来了---");
           return 1;
        }).thenAccept(v->{
            System.out.println("任务第二阶段---");
            System.out.println("第一阶段结果v: "+v);
        }).thenApply(v->{
            System.out.println("任务第三阶段---");
            System.out.println("第二阶段结果v:"+v);
            return null;
        });

        System.out.println("CompletableFuture结果:"+completableFuture.join());


    }

}
